package com.eulog.gwt.euloggwtlibrary.user.client.ui;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Event;

public class EulogDOM {
	
	public static boolean isIE6() {
		if(isIE6Impl()==1) return true;
		return false;
	}

	private static native int isIE6Impl() /*-{
		if(navigator.userAgent.toLowerCase().indexOf("msie 6.0") != -1) return 1;
		 return 0;
	}-*/;
	
	public static boolean isCompleted(JavaScriptObject obj) {
		if(isCompletedImpl(obj)==1) return true;
		return false;
	}
	
	private static native int isCompletedImpl(JavaScriptObject obj) /*-{
	
		if(obj == null) return 0;
		if(obj.complete==true) return 1;
		
		return 0;
	}-*/;
	
	public static Event getIE6OnloadEvent() {
		if (isIE6()) return getIE6OnloadEventImpl();
		
		return null;
	}
	
	private static native Event getIE6OnloadEventImpl() /*-{
		var event = $doc.createEventObject();
		event.type = 'load';
		return event; 
	}-*/;
	
	public static String getWndVariable(String name) {
		return getWndVariableStringImpl(name);
	}
	
	private static native java.lang.String getWndVariableStringImpl(String name) /*-{
		return $wnd[name]?$wnd[name]:"";
	}-*/;
	
	public static int getWndVariable2int(String name) {
		return getWndVariableIntImpl(name);
	}
	
	private static native int getWndVariableIntImpl(String name) /*-{
	return $wnd[name]?$wnd[name]:"";
}-*/;
	
}
